//
//  ServersManager.m
//  jboss-admin
//
//  Created by Christos Vasilakis on 19/07/2010.
//  Copyright 2010 All rights reserved.
//

#import "ServersManager.h"

static ServersManager *SharedServersManager = nil;

@implementation ServersManager

@synthesize list;

+ (ServersManager *)sharedServersManager {
	if (SharedServersManager == nil) {
		SharedServersManager = [[super allocWithZone:NULL] init];
	}
	
	return SharedServersManager;
}

-(id)init {
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);	
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Servers.archive"];
	
	NSData *data;
	NSKeyedUnarchiver *unarchiver;
	
	data = [[NSData alloc] initWithContentsOfFile:path];
	unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
	
	list = [unarchiver decodeObjectForKey:@"Servers"];
	
	[unarchiver finishDecoding];
	[unarchiver release];
	[data release];
	
	return (self);
}

+ (id)allocWithZone:(NSZone *)zone {
    return [self sharedServersManager];
}

- (id)copyWithZone:(NSZone *)zone {
    return self;
}

- (id)retain {
    return self;
}

- (NSUInteger)retainCount {
    return NSUIntegerMax;  //denotes an object that cannot be released
}

- (void)release {
    //do nothing
}

- (id)autorelease {
    return self;
}
@end
